﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls.Maps;

namespace GeoLocationSharing
{
    public class GoogleMaps
    {
        GTile _gootile;
               
        public GoogleMaps()
        {
            _gootile = new GTile();
        }

        public bool SetTileMode(GTileMode Mode)
        {
            _gootile.TileMode = (char)Mode;
             return true;
        }

        public bool SetServerId(int Id)
        {
            _gootile.ServerID = Id;
            return true;
        }
        
        
    }

    /// <summary>
    /// Different views available for the app
    /// </summary>
    public enum GTileMode
    {
        Hybrid = 'y',
        Physical = 't',
        Street = 'm',
        Satellite = 's'
    }

    class GTile : TileSource
    {
        int _server_id = 0;
        char _tile_mode = 'y';

        /// <summary>
        /// Server ID to use for tile request
        /// </summary>
        public int ServerID
        {
            get { return _server_id; }
            set { _server_id = value; }
        }

        public char TileMode
        {
            get
            {
                return _tile_mode;
            }
            set
            {
                _tile_mode = value;
            }
        }

        /// <summary>
        /// Provides direct control over access to Google maps.
        /// </summary>
        public GTile()
        {
            UriFormat = @"http://mt{0}.google.com/vt/lyrs={1}&z={2}&x={3}&y={4}";
        }

        public override Uri GetUri(int x, int y, int ZoomLevel)
        {
            if (ZoomLevel >= 0)
            {
                string _uri = string.Format(UriFormat, _server_id, _tile_mode, ZoomLevel, x, y);
                return new Uri(_uri);
            }
            string _neg_zoom_uri = string.Format(UriFormat, _server_id, _tile_mode, 0, x, y);
            return new Uri(_neg_zoom_uri);
        }

    }

    class TestClass
    {
        TestClass()
        {
            GoogleMaps maps = new GoogleMaps();
        }
    }
}
